//package com.dh.spring.thread;
//
//import com.dh.spring.client.SocketFileUploadRunnable;
//import com.dh.spring.common.BasicConstant;
//import com.dh.spring.util.LocalTime;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.*;
//
//public class ThreadTest {
//    private static final Logger logger = LoggerFactory.getLogger(SocketFileUploadRunnable.class);
//    public static void main(String[] args) {
//        ThreadTest threadTest = new ThreadTest();
//
//        //TODO 测试线程池
//        threadTest.testThreadPool();
//    }
//
//    private void testThreadPool() {
//        List<Callable<String>> list = new ArrayList<Callable<String>>();
//        for(int i = 0; i < 10; i++) {
//            list.add(new CallableThread());
//        }
//
//        ExecutorService executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors()
//            , Runtime.getRuntime().availableProcessors()
//            , 1000
//            , TimeUnit.MILLISECONDS
//            , new SynchronousQueue<>());
//
//        int success = 0;
//        try {
//            List<Future<String>> resultList = executorService.invokeAll(list);
//            for(Future<String> future : resultList) {
//                if(future.get().equals(BasicConstant.SEND_SUCCESS)) {
//                    success++;
//                }
//            }
//            logger.info("[" + LocalTime.formatDate(LocalDateTime.now())
//                + "] ----------- 当前待上传的文件个数：[ " + success + " ] -----------");
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        }
//    }
//
//    static class CallableThread implements Callable<String> {
//
//        @Override
//        public String call() throws Exception {
//            logger.info("[" + LocalTime.formatDate(LocalDateTime.now())
//                    + "] ----------- 当前线程 [ " + Thread.currentThread().getName() + " ] 执行耗时任务...... -----------");
//            TimeUnit.MILLISECONDS.sleep(5);
//            return "success";
//        }
//    }
//}
